﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.Common;
using System.Data;
using MaxLeaf.DB;

namespace MaxLeaf.DAL
{
    public class t_SubMessageDALBuilder: BaseDALBuilder
    {
        public t_SubMessageDALBuilder()
            : base()
        {
            K3DAL = new K3.t_SubMessageDAL();

            WebDAL = new Web.mary_t_SubMessageDAL();
        }

        protected override bool ValidCheckOrgData(ServerInfo orgServer, DataRowView drvLog)
        {
            if (!orgServer.MasterDB)
            {
                //主账套分发
                LogManager.Debug(string.Format("{0} MasterDB {1}   ", orgServer, orgServer.MasterDB));
                return false;
            }
            if ((LogStatus)CvtFunc.ToInt(drvLog[DEL.LogDEL.LogStatus]) == LogStatus.Delete)
            {
                return true;
            }
            using (DBAccess dbOrgCon = new DBAccess(orgServer))
            {
                DataRow drOrgData = dbOrgCon.GetTableDataFirstRow("t_SubMessage", new Dictionary<string, object>() { { "FInterID", drvLog[DEL.LogDEL.KeyValue] } });
                if (drOrgData == null)
                {
                    return false;
                }
                string strFTypeID=CvtFunc.ToString(drOrgData["FTypeID"]);
                //只分发客户、物料分类
                if (!(strFTypeID.Equals("501") || strFTypeID.Equals("504") || strFTypeID.Equals("10002")))
                {

                    LogManager.Debug(string.Format("t_SubMessage {0} FTypeID is {1} 不分发", drvLog[DEL.LogDEL.KeyValue],strFTypeID));
                    return false;
                }
            }

            return base.ValidCheckOrgData(orgServer, drvLog);
        }
    }
}
